home *** CD-ROM | disk | FTP | other *** search
/ Champak 140 / (Vol 140) Sep 19 2011.iso / Games / world-wars.swf / scripts / __Packages / classes / ww_interface / Fightbox.as < prev    next >
Encoding:
Text File  |  2011-09-19  |  8.6 KB  |  295 lines

  1. class classes.ww_interface.Fightbox extends MovieClip
  2. {
  3.    var EXPLOSION_MC;
  4.    var UNITS_MC;
  5.    var SKIP_MODE;
  6.    var SKIP;
  7.    var GAME_CLASS;
  8.    var LAST_FIGHT;
  9.    var military1;
  10.    var military2;
  11.    var explosion1;
  12.    var explosion2;
  13.    var ter1;
  14.    var ter2;
  15.    var WINNER;
  16.    var winTemp;
  17.    var winNO;
  18.    var ran1;
  19.    var ran2;
  20.    var onEnterFrame;
  21.    var dieces_limit;
  22.    var dieces_no;
  23.    var rubbish;
  24.    var ultraSkipA;
  25.    var ultraSkipB;
  26.    var ultraSkipP1;
  27.    var ultraSkipP2;
  28.    var docX;
  29.    var i;
  30.    function Fightbox()
  31.    {
  32.       super();
  33.       this.EXPLOSION_MC = this._parent._parent.EXPLOSION_MC;
  34.       this.UNITS_MC = this._parent._parent.UNITS_MC;
  35.       var root = this;
  36.       this.SKIP_MODE = false;
  37.       this._visible = false;
  38.       var _loc4_ = 1;
  39.       while(_loc4_ <= 8)
  40.       {
  41.          this["d" + _loc4_]._visible = false;
  42.          _loc4_ = _loc4_ + 1;
  43.       }
  44.       this.SKIP.onRelease = function()
  45.       {
  46.          _global.SOUNDS.playSound("Click- g┼éo┼¢niejszy.wav");
  47.          root.SKIP_MODE = true;
  48.          root._visible = false;
  49.          root.ultraSkip();
  50.       };
  51.    }
  52.    function registerGame(g)
  53.    {
  54.       this.GAME_CLASS = g;
  55.    }
  56.    function fight(A, B)
  57.    {
  58.       if(!this.SKIP_MODE)
  59.       {
  60.          this.LAST_FIGHT = getTimer();
  61.          this.resetDieces();
  62.          this._visible = true;
  63.          this.military1._visible = this.military2._visible = true;
  64.          this.explosion1.gotoAndStop(1);
  65.          this.explosion2.gotoAndStop(1);
  66.          this.military1.un.text = A.unitsNO;
  67.          this.military2.un.text = B.unitsNO;
  68.          this.military1.army_ico.gotoAndStop(A.army);
  69.          this.military1.army_ico.filters = [];
  70.          this.military1.army_ico.units.gotoAndStop(A.unitsNO);
  71.          this.military1.flag.gotoAndStop(A.player);
  72.          this.military2.army_ico.gotoAndStop(B.army);
  73.          this.military2.army_ico.filters = [];
  74.          this.military2.army_ico.units.gotoAndStop(B.unitsNO);
  75.          this.military2.flag.gotoAndStop(B.player);
  76.          this.ter1.gotoAndStop(A.player);
  77.          this.ter2.gotoAndStop(B.player);
  78.          var _loc8_ = 0;
  79.          var _loc7_ = 0;
  80.          this.WINNER = undefined;
  81.          var _loc5_ = 0;
  82.          while(_loc5_ < A.unitsNO)
  83.          {
  84.             var _loc6_ = this.random2(5) + 1;
  85.             _loc8_ += _loc6_;
  86.             _loc5_ = _loc5_ + 1;
  87.          }
  88.          _loc5_ = 0;
  89.          while(_loc5_ < B.unitsNO)
  90.          {
  91.             _loc6_ = this.random2(5) + 1;
  92.             _loc7_ += _loc6_;
  93.             _loc5_ = _loc5_ + 1;
  94.          }
  95.          if(_loc8_ > _loc7_)
  96.          {
  97.             this.winTemp = A;
  98.             this.winNO = 1;
  99.          }
  100.          else
  101.          {
  102.             this.winTemp = B;
  103.             this.winNO = 2;
  104.          }
  105.          this.setUltraSkip(_loc8_,_loc7_,A,B);
  106.          this.ran1.setTo(_loc8_);
  107.          this.ran2.setTo(_loc7_);
  108.          _global.SOUNDS.playSound("ko┼¢ci.wav");
  109.          this.onEnterFrame = mx.utils.Delegate.create(this,this.fightFinished);
  110.          this.dieces_limit = A.unitsNO + B.unitsNO;
  111.          this.dieces_no = 0;
  112.          this.rubbish = new Array();
  113.          this.throwDices(A.player,A.unitsNO,1);
  114.          this.throwDices(B.player,B.unitsNO,2);
  115.       }
  116.       else
  117.       {
  118.          _loc8_ = 0;
  119.          _loc7_ = 0;
  120.          this.WINNER = undefined;
  121.          _loc5_ = 0;
  122.          while(_loc5_ < A.unitsNO)
  123.          {
  124.             _loc6_ = this.random2(5) + 1;
  125.             _loc8_ += _loc6_;
  126.             _loc5_ = _loc5_ + 1;
  127.          }
  128.          _loc5_ = 0;
  129.          while(_loc5_ < B.unitsNO)
  130.          {
  131.             _loc6_ = this.random2(5) + 1;
  132.             _loc7_ += _loc6_;
  133.             _loc5_ = _loc5_ + 1;
  134.          }
  135.          if(_loc8_ > _loc7_)
  136.          {
  137.             var _loc9_ = this;
  138.             this.EXPLOSION_MC._x = this.UNITS_MC._x + B.unitsMC._x;
  139.             this.EXPLOSION_MC._y = this.UNITS_MC._y + B.unitsMC._y;
  140.             this.EXPLOSION_MC.gotoAndPlay(2);
  141.             this.winTemp = A;
  142.             this.EXPLOSION_MC.onEnterFrame = mx.utils.Delegate.create(this,this.fightFinished2);
  143.          }
  144.          else
  145.          {
  146.             this.EXPLOSION_MC._x = this.UNITS_MC._x + A.unitsMC._x;
  147.             this.EXPLOSION_MC._y = this.UNITS_MC._y + A.unitsMC._y;
  148.             this.EXPLOSION_MC.gotoAndPlay(2);
  149.             this.winTemp = B;
  150.             this.EXPLOSION_MC.onEnterFrame = mx.utils.Delegate.create(this,this.fightFinished2);
  151.          }
  152.       }
  153.    }
  154.    function setUltraSkip(pow1, pow2, A, B)
  155.    {
  156.       this.ultraSkipA = A;
  157.       this.ultraSkipB = B;
  158.       this.ultraSkipP1 = pow1;
  159.       this.ultraSkipP2 = pow2;
  160.    }
  161.    function ultraSkip()
  162.    {
  163.       delete this.onEnterFrame;
  164.       if(this.ultraSkipP1 > this.ultraSkipP2)
  165.       {
  166.          var _loc2_ = this;
  167.          this.EXPLOSION_MC._x = this.UNITS_MC._x + this.ultraSkipB.unitsMC._x;
  168.          this.EXPLOSION_MC._y = this.UNITS_MC._y + this.ultraSkipB.unitsMC._y;
  169.          this.EXPLOSION_MC.gotoAndPlay(2);
  170.          this.winTemp = this.ultraSkipA;
  171.          this.EXPLOSION_MC.onEnterFrame = mx.utils.Delegate.create(this,this.fightFinished2);
  172.       }
  173.       else
  174.       {
  175.          this.EXPLOSION_MC._x = this.UNITS_MC._x + this.ultraSkipA.unitsMC._x;
  176.          this.EXPLOSION_MC._y = this.UNITS_MC._y + this.ultraSkipA.unitsMC._y;
  177.          this.EXPLOSION_MC.gotoAndPlay(2);
  178.          this.winTemp = this.ultraSkipB;
  179.          this.EXPLOSION_MC.onEnterFrame = mx.utils.Delegate.create(this,this.fightFinished2);
  180.       }
  181.    }
  182.    function initCountdowns()
  183.    {
  184.       this.ran1.countTo();
  185.       this.ran2.countTo();
  186.    }
  187.    function fightFinished()
  188.    {
  189.       if(this.SKIP_MODE == false)
  190.       {
  191.          if(this.ran1.finished() && this.ran2.finished() && this.explosion1._currentframe == 1 && this.explosion2._currentframe == 1)
  192.          {
  193.             if(this.winNO == 1)
  194.             {
  195.                this.explosion2.gotoAndPlay(2);
  196.             }
  197.             else
  198.             {
  199.                this.explosion1.gotoAndPlay(2);
  200.             }
  201.          }
  202.          if(this.explosion1._currentframe == 7)
  203.          {
  204.             this.military1._visible = false;
  205.          }
  206.          if(this.explosion2._currentframe == 7)
  207.          {
  208.             this.military2._visible = false;
  209.          }
  210.          if(this.explosion1._currentframe == this.explosion1._totalframes || this.explosion2._currentframe == this.explosion2._totalframes)
  211.          {
  212.             this.WINNER = this.winTemp;
  213.             this.GAME_CLASS.fightFinished();
  214.             this._visible = false;
  215.             delete this.onEnterFrame;
  216.          }
  217.       }
  218.    }
  219.    function fightFinished2()
  220.    {
  221.       if(this.EXPLOSION_MC._currentframe == 7)
  222.       {
  223.          this.WINNER = this.winTemp;
  224.          this.GAME_CLASS.fightFinished();
  225.       }
  226.       if(this.EXPLOSION_MC._currentframe == this.EXPLOSION_MC._totalframes)
  227.       {
  228.          delete this.EXPLOSION_MC.onEnterFrame;
  229.       }
  230.    }
  231.    function random2(z)
  232.    {
  233.       return Math.round(Math.random() * z);
  234.    }
  235.    function throwDices(player, units, terr)
  236.    {
  237.       var root = this;
  238.       var i = 0;
  239.       while(i < units)
  240.       {
  241.          var _loc2_ = this["d" + player].duplicateMovieClip("dice" + player + "_" + i,terr * 10 + i);
  242.          this.rubbish.push(_loc2_);
  243.          _loc2_._x = this["gen" + terr]._x;
  244.          _loc2_._xscale = _loc2_._yscale = 70;
  245.          if(terr == 1)
  246.          {
  247.             _loc2_.docX = _loc2_._x + 15;
  248.          }
  249.          if(terr == 2)
  250.          {
  251.             _loc2_.docX = _loc2_._x - 15 - _loc2_._width;
  252.          }
  253.          _loc2_._y = this["gen" + terr]._y + i * 25;
  254.          _loc2_.i = (i + 2) / 2;
  255.          _loc2_.onEnterFrame = function()
  256.          {
  257.             this._x += (this.docX - this._x) / this.i;
  258.             if(Math.abs(this._x - this.docX) < 1)
  259.             {
  260.                root.dieces_no = root.dieces_no + 1;
  261.                if(root.dieces_no == root.dieces_limit)
  262.                {
  263.                   root.initCountdowns();
  264.                }
  265.                this._x = this.docX;
  266.                delete this.onEnterFrame;
  267.             }
  268.          };
  269.          i++;
  270.       }
  271.    }
  272.    function resetWinner()
  273.    {
  274.       this.WINNER = undefined;
  275.    }
  276.    function resetSkipMode()
  277.    {
  278.       this.SKIP._visible = true;
  279.       this.SKIP_MODE = false;
  280.    }
  281.    function resetDieces()
  282.    {
  283.       var _loc2_ = 0;
  284.       while(_loc2_ < this.rubbish.length)
  285.       {
  286.          this.rubbish[_loc2_].removeMovieClip();
  287.          _loc2_ = _loc2_ + 1;
  288.       }
  289.    }
  290.    function kill()
  291.    {
  292.       delete this.EXPLOSION_MC.onEnterFrame;
  293.    }
  294. }
  295.